package com.lych.dubbo.api;

import com.lych.model.mongo.Soul;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class SoulApiImpl implements SoulApi{

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 通过问卷id查询问卷详细信息
     * @param soulIds
     * @return
     */
    @Override
    public List<Soul> findByIds(List<String> soulIds) {
        List<Soul> list = new ArrayList<>();
        for (String soulId : soulIds) {
            Query query = Query.query(Criteria.where("id").is(soulId));
            Soul soul = mongoTemplate.findOne(query, Soul.class);
            list.add(soul);
        }
        return list;
    }
}
